<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Block</title>
</head>

<body>
<?php
include("../connection/connection.php");
include("reportFunctions.php");
$distId=$_REQUEST['distId'];
//$sqlReport = "SELECT district_id,name_scheme,village_id,sum(present_population) as present_population FROM `tbl_dtls_q1_main` where `district_id` = ".$distId." and type_scheme='RWSS' group by name_scheme";
//echo $sqlReport;
$sqlReport = "SELECT district_id,name_scheme,village_id,present_population FROM `tbl_dtls_q1_main` where `district_id` = ".$distId." and type_scheme='RWSS'";
$queryReport = mysql_query($sqlReport);

function getInstalledCapSchemeName($distId,$name_scheme)
{
	$sqlStorage="Select sum(reserv_cap) FROM `tbl_dtls_q1_reserv` WHERE `loc_id` IN (SELECT DISTINCT id FROM tbl_dtls_q1_main WHERE district_id =".$distId." AND  `name_scheme` = '".$name_scheme."')";
	$queryStorage=mysql_query($sqlStorage);
	$rowStorage=mysql_fetch_row($queryStorage);
	return $rowStorage[0];
}

function getActualWaterSupplySchemeName($distId,$name_scheme)
{
	$sqlActual="Select water_supply FROM `tbl_dtls_q1_last` WHERE `loc_id` IN (SELECT DISTINCT id FROM tbl_dtls_q1_main WHERE district_id =".$distId." AND  `name_scheme` = '".$name_scheme."')";
	$queryActual=mysql_query($sqlActual);
	$rowActual=mysql_fetch_row($queryActual);
	return $rowActual[0];
}

?>
<table border="0" width="809" cellspacing="0" cellpadding="0">
	<tr>
		<td bgcolor="#E9E9E9" height="26">
		<p align="center"><span style="font-size: 9pt; font-weight: 700">
		<font face="Verdana" color="#224568">Scheme wise coverage of villages under regional schemes</font></span></td>
	</tr>
	
	<tr>
		<td bgcolor="#E9E9E9" height="56">
		<table border="1" width="809" cellspacing="0" cellpadding="0" height="47" bgcolor="#C5D8EB">
			<tr>
				
				<td width="50" align="center">
				<font style="font-size: 8.5pt" face="Verdana"><b>Sr.No.</b></font></td>
				<td width="123" align="center">
				<p align="center"><font face="Verdana" style="font-size: 8.5pt"><b>
				Name of Scheme</b></font></td>
				
				<td width="99" align="center">
				<font style="font-size: 8.5pt" face="Verdana"><b>No. of villages covered (No.)</b></font></td>
				<td width="99" align="center">
				<font style="font-size: 8.5pt" face="Verdana"><b>Population 2010</b></font></td>
				<td width="99" align="center">
				<font style="font-size: 8.5pt" face="Verdana"><b>Actual water supplied(KLD)</b></font></td>
				<td width="113" align="center">
				<font face="Verdana" style="font-size: 8.5pt"><b>Installed storage capacity 
				(KL)</b></font></td>
				
				<td align="center" width="117">
				<font style="font-size: 8.5pt" face="Verdana"><b>Storage 
				capacity required (rounded off to one KL as per norms)</b></font></td>
				<td width="116" align="center">
				<font style="font-size: 8.5pt" face="Verdana"><b>Sufficiency of 
				installed storage capacity (%)</b></font></td>
			</tr>
		
	<tr>
		
		<?php
			$slNo=1;
			while($rowReport = mysql_fetch_array($queryReport)) {
			//$sn=1;
			//$storageCWR=0;
			//$storageGLR=0;
			//$storageGLSR=0;
			//$storageOHSR=0;
			if(($rowReport['district_id']==389) || ($rowReport['district_id']==390) || ($rowReport['district_id']==391) || ($rowReport['district_id']==398) || ($rowReport['district_id']==392) || ($rowReport['district_id']==401) || ($rowReport['district_id']==402) || ($rowReport['district_id']==403) || ($rowReport['district_id']==404) || ($rowReport['district_id']==405) || ($rowReport['district_id']==406) || ($rowReport['district_id']==416))
			{
			$lpcd=70;
			}else{
			$lpcd=40;
			}
		?>
			
			
			
			<tr bgcolor="#F9F9F9">
				<td width="50" align="center">
				<font style="font-size: 8.5pt" face="Verdana"><?php echo $slNo;?></font></td>
				<td align="left" width="124" valign="top"><font face="Verdana" style="font-size: 8.5pt"><?php echo $rowReport['name_scheme']; ?></font></td>
				<?php 
				$rwss=explode(',',$rowReport['village_id']);
				$countrwss=count($rwss);
				?>
				<td align="center" width="103"><font face="Verdana" style="font-size: 8.5pt"><?php echo $countrwss;?></font></td>
				<td align="center" width="103"><font face="Verdana" style="font-size: 8.5pt"><?php echo $prestPop=$rowReport['present_population'];?></font></td>
				<td align="center" width="103"><font face="Verdana" style="font-size: 8.5pt">
				<?php
				$actualwater=getActualWaterSupplySchemeName($distId,$rowReport['name_scheme']);
				if($actualwater=='')
				{
					echo "0.00";
				}
				else
				{
					echo number_format($actualwater,2,'.','');
				}
				//echo $countrwss;?></font></td>
				<td align="center" width="112"><font face="Verdana" style="font-size: 8.5pt"><?php 
				
				$installcap=getInstalledCapSchemeName($distId,$rowReport['name_scheme']);
				if($installcap=='')
				{
					echo "0.00";
				}
				else
				{
					echo number_format($installcap,2,'.','');
				} 
				
				?></font></td>
				
				<td width="117" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo $storagecap=number_format($rowReport['present_population']*$lpcd/1000,2,'.',''); ?></font></td>
				<td align="center" width="116"><font face="Verdana" style="font-size: 8.5pt"><?php if($storagecap==0){echo "0.00"; } else { echo number_format(($installcap*100)/$storagecap,2,'.',''); }?></font></td>
			</tr>
			
			
			<?php 
			//$slNo++;
			$slNo++;
			$totalvill+=$countrwss;
			$totalactual+=$actualwater;
			$totalinst+=$installcap;
			$totalstoragecap+=$storagecap;
			$storageCapGrandTot+=$storagecap;
			$totPrestPop+=$prestPop;
			} ?>
			
			<tr>
				
				<td  bgcolor="#E9E9E9" align="center" width="124" height="25" colspan="2"><font face="Verdana" style="font-size: 8.5pt"><b>Total</b></font></td>
				
				<td align="center" bgcolor="#E9E9E9" width="103"><font face="Verdana" style="font-size: 8.5pt"><b><?php echo $totalvill;?></b></font></td>
				<td align="center" bgcolor="#E9E9E9" width="103"><font face="Verdana" style="font-size: 8.5pt"><b><?php echo $totPrestPop;?></b></font></td>
				<td align="center" bgcolor="#E9E9E9" width="103"><font face="Verdana" style="font-size: 8.5pt"><b><?php echo number_format($totalactual,2,'.','');?></b></font></td>
				<td align="center" bgcolor="#E9E9E9" width="112"><font face="Verdana" style="font-size: 8.5pt"><b><?php echo number_format($totalinst,2,'.',''); ?></b></font></td>
				
				<td align="center" bgcolor="#E9E9E9"><font face="Verdana" style="font-size: 8.5pt"><b><?php echo number_format($totalstoragecap,2,'.','');?></b></font></td>
				<td align="center" width="116" bgcolor="#E9E9E9"><font face="Verdana" style="font-size: 8.5pt"><b><?php if($totalstoragecap==0){echo "0.00"; } else { echo number_format(($totalinst*100)/$totalstoragecap,2,'.',''); }?></b></font></td>
			</tr>
			
			
			
		</table>		</td>
	</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>



</body>

</html>